package createThread.cn.tedu.threaddemo.test8;

import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Demo2 {
    public static void main(String[] args) {
        BlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue<>(100);

        Thread t1 = new Thread(()->{
            int num = 0;
            while(true){
                try {
                    blockingQueue.put(num);
                    System.out.println("put的元素: " + num);
                    num++;
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(()->{
            while(true){
                try {
                    int n = (int) blockingQueue.take();
                    System.out.println("take的元素: " + n);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t1.start();
        t2.start();
    }
}
